home *** CD-ROM | disk | FTP | other *** search
/ SuperView Productivity Suite 2 / SuperView Productivity Suite 2.iso / BONUS / Support / SVConvert / SVConvert.dopus5 next >
Encoding:
Text File  |  1999-08-21  |  15.1 KB  |  493 lines

  1. /*
  2.   $VER: SVConvert.dopus5 1.2a (21.08.99)
  3.  
  4.   Written by Wayne Newark <wayne@zahadum.u-net.com>, using GoldEd/Pro.
  5.  
  6.   This is an ARexx script for DOpus Magellan that allows you to use Andreas
  7.   Kleinert's excellent SViewNG/SViewII to convert picture files from one format to
  8.   another. It processes all files selected in one or more source listers, ignoring
  9.   those it does not recognise.
  10.  
  11.   It will only work with a registered version of SViewNG/SViewII.
  12.  
  13.   This script can handle both multiple source and destination listers. All the
  14.   selected source files, from all the source listers, will be converted into
  15.   all the destination listers. As part of the conversion process the files are
  16.   renamed. It does this by stripping off all text after the last '.' and
  17.   appending an appropriate suffix.
  18.  
  19.   Example: Converting to PNG - Pic1.iff becomes Pic1.PNG
  20.            Converting to GIF - Pic2.pcx becomes Pic2.GIF
  21.  
  22.   ---------------------------------------------------------------------------
  23.  
  24.   Usage: ARexx     DOpus5:ARexx/SVConvert.dopus5 {Qp} format
  25.  
  26.   format - At present this is limited to: JPEG, BMP, PNG, DEEP, PCX,
  27.                                           ILBM, PBM, RGFX, TIFF and SVG.
  28.  
  29.   Read the Superview-library.guide for further details on supported graphic
  30.   formats.
  31.  
  32.   ---------------------------------------------------------------------------
  33.  
  34.   History:
  35.  
  36.   Read document svconvert.history for details of changes.
  37.  
  38. */
  39.  
  40. signal on Syntax                                /* intercept syntax errors                      */
  41. options results                                 /* need results                                 */
  42. options failat 11                               /* external commands are allowed return code 10 */
  43. lf='a'x                                         /* ascii code for linefeed                      */
  44.  
  45. SV_path = 'Serious:Graphics/Superview/SViewII'  /* Location and name of SuperView program       */
  46. SV_port = 'SViewII.rx'                          /* Name of SuperView ARexx Port                 */
  47.  
  48. call Initialise
  49.  
  50. parse arg DOpus_port ' ' format
  51.  
  52. if DOpus_port='' then
  53.     DOpus_port='DOPUS.1'
  54.  
  55. address value DOpus_port
  56.  
  57. lister query source stem sl
  58. if sl.count=0 then
  59.     do
  60.         dopus request '"'txt_nosrc'"' txt_okay
  61.         exit
  62.     end
  63.  
  64. lister query dest stem dl
  65. if dl.count=0 then
  66.     do
  67.         dopus request '"'txt_nodest'"' txt_okay
  68.         exit
  69.     end
  70.  
  71. /* set variables depending on required output format */
  72.  
  73. do i=0 to sv.count-1
  74.     parse var sv.i sv_format '|' sv_suffix '|' sv_compression '|' sv_savetype1 '|' sv_savetype2
  75.     if sv_format=format then
  76.         do
  77.             suffix=sv_suffix
  78.             savetype=sv_savetype1
  79.             if sv_compression='Y' then
  80.                 do
  81.                     dopus request '"'txt_compress'"' txt_yesno
  82.                     if rc=1 then
  83.                         savetype=sv_savetype2
  84.                 end
  85.             leave
  86.         end
  87. end
  88.  
  89. if savetype='' then
  90.     do
  91.         dopus request '"'txt_format'"' txt_okay
  92.         exit
  93.     end
  94.  
  95. /* Start Superview if not already running */
  96.  
  97. if ~show('p',SV_port) then
  98.     do
  99.         address command 'run >NIL: 'SV_path' -INSTALL_APPMENU=FALSE -INSTALL_APPICON=FALSE -INSTALL_APPWINDOW=FALSE'
  100.         address command 'WaitForPort 'SV_port
  101.         if ~show('p',SV_port) then /* If SuperView fails to start, an error is reported.  */
  102.             do
  103.                 dopus request '"'txt_sv_notfnd'"' txt_okay
  104.                 exit
  105.             end
  106.         SV_Started=1
  107.     end
  108.  
  109. address value SV_port
  110. "PUT_ICONS=NO"
  111. "ERROR_REPORT=NO"
  112. address value DOpus_port
  113.  
  114. /* lock the listers here!!! */
  115.  
  116. do s=0 to sl.count-1
  117.     lister set sl.s busy on
  118. end
  119.  
  120. do d=0 to dl.count-1
  121.     lister set dl.d busy on
  122. end
  123.  
  124. /* process source lister(s) */
  125.  
  126. do s=0 to sl.count-1
  127.     lister query sl.s path /* get path of current source lister */
  128.     src_path=strip(result,"B",'"')
  129.     lister query sl.s numselfiles /* get number of selected files */
  130.     number_files=result
  131.     lister query sl.s numselentries /* get total number of selected items */
  132.     total_selected=result
  133.     if number_files>0 then
  134.         do
  135.             complete=(1+dl.count)*number_files
  136.             sofar=0
  137.             lister clear sl.s abort
  138.             lister set sl.s newprogress abort bar name title
  139.             lister set sl.s newprogress title txt_title
  140.             lister set sl.s newprogress bar complete sofar
  141.             do t=1 to total_selected
  142.                 sofar=sofar+1 /* increase progress position */
  143.                 lister query sl.s firstsel /* obtain selected item */
  144.                 src_name=strip(result,"B",'"')
  145.                 lister query sl.s entry src_name stem fileinfo /* check for directories */
  146.                 if fileinfo.type<0 then
  147.                     do
  148.                         /* check for icons (those with .info suffix) and ignore them */
  149.                         if right(src_name,5)~='.info' then
  150.                             do
  151.                                 lister set sl.s newprogress name txt_loading||src_name
  152.                                 lister set sl.s newprogress bar complete sofar
  153.                                 call Load_File
  154.                                 if SV_status~='No file loaded' then
  155.                                     do
  156.                                         lister query sl.s abort
  157.                                         if result then
  158.                                             do
  159.                                                 lister set sl.s newprogress off
  160.                                                 dopus request '"'txt_aborted'"' txt_okay
  161.                                                 call The_End
  162.                                                 exit
  163.                                             end
  164.                                         call Convert_File
  165.                                         do d=0 to dl.count-1 /* now save file to all destinations */
  166.                                             sofar=sofar+1 /* increase progress position */
  167.                                             if dl.count>1 then
  168.                                                 lister set sl.s newprogress name txt_saving||dest_name||" "||d+1
  169.                                             else
  170.                                                 lister set sl.s newprogress name txt_saving||dest_name
  171.                                             lister set sl.s newprogress bar complete sofar
  172.                                             call Save_File
  173.                                             lister query sl.s abort
  174.                                             if result then
  175.                                                 do
  176.                                                     lister set sl.s newprogress off
  177.                                                     dopus request '"'txt_aborted'"' txt_okay
  178.                                                     call The_End
  179.                                                     exit
  180.                                                 end
  181.                                         end /* end of do */
  182.                                         call Delete_File
  183.                                     end
  184.                                 else
  185.                                     do
  186.                                         sofar=sofar+dl.count
  187.                                         lister select sl.s src_name off /* deselect current file (invalid format) */
  188.                                     end
  189.                             end
  190.                         else
  191.                             do
  192.                                 sofar=sofar+dl.count
  193.                                 lister select sl.s src_name off /* deselect current file (#?.info) */
  194.                             end
  195.                     end
  196.                 else
  197.                     do
  198.                         lister select sl.s src_name off /* deselect current directory */
  199.                     end
  200.                 lister refresh sl.s /* refresh current source lister */
  201.             end /* end of do */
  202.             lister set sl.s newprogress off
  203.         end
  204. end
  205.  
  206. call The_End
  207.  
  208. exit
  209.  
  210. Syntax:
  211.  
  212. call The_End
  213.  
  214. address value DOpus_port
  215. dopus request '"'txt_error_fnd'"' txt_okay
  216.  
  217. exit
  218.  
  219.  
  220. /*** Called subroutines or functions follow ***/
  221.  
  222.  
  223. /*
  224. **  Tidies up listers etc.
  225. */
  226.  
  227. The_End:
  228.  
  229. /* Reread all destination listers */
  230.  
  231. /* Unlock any locked listers */
  232.  
  233.     do s=0 to sl.count-1
  234.         lister set sl.s busy off
  235.     end
  236.  
  237.     do d=0 to dl.count-1
  238.         lister query dl.d path /* obtain path of destination lister */
  239.         dest_path=strip(result,"B",'"')
  240.         lister set dl.d busy off
  241.         lister read dl.d dest_path
  242.     end
  243.  
  244. /* Quit Superview if started by this script */
  245.  
  246.     if SV_Started then
  247.         if show('p',SV_port) then
  248.             do
  249.                 address value SV_port
  250.                 "QUIT"
  251.             end
  252.     else
  253.         do
  254.            address value SV_port
  255.            "ERROR_REPORT=YES"
  256.         end
  257.  
  258.     return
  259.  
  260.  
  261. /*
  262. **   Sets Output File Format and creates new destination file name
  263. */
  264.  
  265. Convert_File:
  266.  
  267.     lang=length(src_name)
  268.     posn=lastpos('.',src_name)
  269.     po=lang-posn
  270.  
  271.     /* rename destination filename */
  272.  
  273.     if posn=0 then
  274.         dest_name=src_name || '.' || suffix
  275.     else
  276.         do
  277.             suffix_old=right(src_name,po)
  278.             dest_name=left(src_name,posn) || suffix
  279.         end
  280.  
  281.     if DATATYPE(suffix_old,'N') = 1 then
  282.         dest_name = dest_name || '.' || suffix_old
  283.  
  284.     dest_info.name=dest_name
  285.  
  286.     address value SV_port
  287.     if suffix='GIF' then
  288.         do
  289.             parse var SV_status st ' ' width 'x' height 'x' depth
  290.             if depth>8 then
  291.                 do
  292.                     "SVOPERATOR=Dither24Bit" /* reduces picture to 8 bit */
  293.                     "ACTION"
  294.                 end
  295.         end
  296.  
  297.     interpret '"SAVE_TYPE='savetype'"' /* Sets SuperView Savetype */
  298.  
  299.     return
  300.  
  301.  
  302. /*
  303. **  Causes Superview to save file to destination lister
  304. */
  305.  
  306. Save_File:
  307.  
  308.     address value DOpus_port
  309.  
  310.     lister query dl.d path /* obtain path of destination lister */
  311.     dest_path=strip(result,"B",'"')
  312.  
  313.     dest_file=dest_path||dest_name /* set up complete file name */
  314.  
  315.     if (exists(dest_file) & Overwrite_ind=0) then
  316.         do
  317.             dopus request '"'||dest_file||txt_replace_1'"' txt_replace_2
  318.             if rc=0 then
  319.                 return
  320.             if rc=2 then
  321.                 Overwrite_ind=1
  322.         end
  323.  
  324.     address value SV_port
  325.  
  326.     interpret '"SAVE='||dest_file||'"'
  327.  
  328.     address value DOpus_port
  329.  
  330.     lister addstem dl.d dest_info /* update destination lister */
  331.     lister refresh dl.d
  332.  
  333.     return
  334.  
  335.  
  336. /*
  337. ** Loads current picture into Superview
  338. */
  339.  
  340. Load_File:
  341.  
  342.     src_file=src_path||src_name
  343.  
  344.     address value SV_port
  345.     interpret '"LOAD='||src_file||'"'
  346.     'STATUS=T:SV.status'
  347.  
  348.     if open(ifile,'T:SV.status','R') then
  349.         do
  350.             SV_status=readln(ifile)
  351.             call close ifile
  352.         end
  353.     else
  354.         SV_status='No file loaded'
  355.  
  356.     address value DOpus_port
  357.  
  358.     return
  359.  
  360.  
  361. /*
  362. ** Deletes source file.
  363. **
  364. ** We need to load a dummy file into SViewII so that it frees up the current file
  365. ** for deletion.
  366. */
  367.  
  368. Delete_File:
  369.  
  370.     address value SV_port
  371.     "LOAD=T:SV.status"
  372.     address value DOpus_port
  373.  
  374.     if (exists(src_file) & Delete_ind=0) then
  375.         do
  376.             dopus request '"'||src_name||txt_delete_1'"' txt_delete_2
  377.             select
  378.                 when rc=1 then
  379.                     keep=0
  380.                 when rc=2 then
  381.                     do
  382.                         Delete_ind=1
  383.                         keep=0
  384.                     end
  385.                 when rc=3 then
  386.                     do
  387.                         Delete_ind=2
  388.                         keep=2
  389.                     end
  390.                 otherwise
  391.                     keep=1
  392.             end
  393.         end
  394.  
  395.     lister select sl.s src_name off /* deselect current file */
  396.  
  397.     if (Delete_ind=1 | keep=0) then
  398.         do
  399.             pragma('D', src_path)
  400.             address command 'c:delete ' || src_name || ' QUIET FORCE'
  401.             if rc=0 then
  402.                 lister remove sl.s src_name
  403.         end
  404.  
  405. /*    lister refresh sl.s    refresh current source lister */
  406.  
  407.     return
  408.  
  409.  
  410. /*
  411. ** Initialises variables etc.
  412. */
  413.  
  414. Initialise:
  415.     SV_Started    = 0
  416.     Overwrite_ind = 0
  417.     Delete_ind    = 0
  418.  
  419.     if open(language,'ENV:Language','R') then
  420.         lang = READLN(language)
  421.     else
  422.         lang = 'english'
  423.  
  424.     select
  425.         when lang = 'deutsch' then
  426.             do
  427.                 txt_nosrc     = 'Keine Quelle gewählt.'
  428.                 txt_nodest    = 'Kein Ziel gewählt.'
  429.                 txt_compress  = 'Soll ich mit Kompression speichern?'
  430.                 txt_okay      = 'Ok'
  431.                 txt_yesno     = 'Ja|Nein'
  432.                 txt_format    = 'Unbekanntes Format!'
  433.                 txt_sv_notfnd = 'SViewII kann nicht gestartet werden,'lf'Bitte den Pfad ÜberprÜfen'
  434.                 txt_title     = 'Konvertiere Dateien...'
  435.                 txt_loading   = 'Lade '
  436.                 txt_saving    = 'Sichere '
  437.                 txt_aborted   = 'User Abbruch'
  438.                 txt_error_fnd = 'Ein Fehler ist aufgetreten!'
  439.                 txt_replace_1 = ' existiert bereits.'||lf||'Soll es Überschrieben werden?'
  440.                 txt_replace_2 = 'Ja|Alle|Nein'
  441.                 txt_delete_1  = ' bearbeitet.'||lf||'Soll es gelöscht werden?'
  442.                 txt_delete_2  = 'Ja|Alle|Keines|Nein'
  443.             end
  444.         otherwise
  445.             do
  446.                 txt_nosrc     = 'No source(s) selected.'
  447.                 txt_nodest    = 'No destination(s) selected.'
  448.                 txt_compress  = 'Shall I use compression?'
  449.                 txt_okay      = 'Ok'
  450.                 txt_yesno     = 'Yes|No'
  451.                 txt_format    = 'Unknown Format Specified!'
  452.                 txt_sv_notfnd = 'SViewII can not be started,'lf'check the path'
  453.                 txt_title     = 'Converting files...'
  454.                 txt_loading   = 'Loading '
  455.                 txt_saving    = 'Saving '
  456.                 txt_aborted   = 'User aborted'
  457.                 txt_error_fnd = 'An error has occurred!'
  458.                 txt_replace_1 = ' exists.'||lf||'Shall I overwrite it?'
  459.                 txt_replace_2 = 'Yes|All|No'
  460.                 txt_delete_1  = ' processed.'||lf||'Shall I delete it?'
  461.                 txt_delete_2  = 'Yes|All|None|No'
  462.             end
  463.     end
  464.  
  465. /*
  466.     sv.x - <image format>|<suffix>|<compression available?>|<uncompressed savetype>|<compressed savetype>
  467.  
  468. */
  469.     sv.0          = 'JPEG|jpg|N|JPEG (IJG-JFIF)|x'
  470.     sv.1          = 'BMP|bmp|N|BMP (Win,OS/2)|x'
  471.     sv.2          = 'PNG|png|N|PNG (PiNG)|x'
  472.     sv.3          = 'PCX|pcx|N|PCX V2.5-3.0|x'
  473.     sv.4          = 'DEEP|iff|N|DEEP|x'
  474.     sv.5          = 'ILBM|iff|Y|ILBM uncompressed|ILBM CmpByteRun1'
  475.     sv.6          = 'PBM|pbm|Y|PBM uncompressed|PBM CmpByteRun1'
  476.     sv.7          = 'RGFX|iff|Y|RGFX uncompressed|RGFX XPK-compressed'
  477.     sv.8          = 'SVG|svg|N|SVG Graphics File|x'
  478.     sv.9          = 'TIFF|tiff|N|TIFF V5.0|x'
  479.     sv.10         = 'TGA|tga|N|Targa (TGA)|x'
  480.     sv.11         = 'PGM|pgm|N|PNM PGM (P5)|x'
  481.     sv.12         = 'PPM|ppm|N|PNM PPM (P6)|x'
  482.     sv.13         = 'SGI|sgi|N|SGI|x'
  483.     sv.14         = 'YUVN|iff|N|YUVN (411)|x'
  484.     sv.15         = 'RAS|ras|N|SunRaster (RAS)|x'
  485.     sv.16         = 'ACBM|iff|N|ACBM uncompressed|x'
  486.  
  487.     sv.count      = 17
  488.  
  489.     savetype      = ''
  490.     suffix        = ''
  491.  
  492.     return
  493.